﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace MikeProject002
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.label1.Text = "Best";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            label1.Text = "Basic";
        }

        private void button3_MouseClick(object sender, MouseEventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            
        }

        private void button3_click2(object sender, EventArgs e)
        {
            //MessageBox.Show("Show");

        }

        private void button4_Click(object sender, EventArgs e)
        {
            listBox1.Items.Add(textBox1.Text);
            textBox1.Text = "Введите текст для добавления";
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button5_Click(object sender, EventArgs e)
        {
            listBox1.Sorted = !listBox1.Sorted;
        }

        private void считатьДанныеИзConfigToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MyClasses.Class_001_Static.F_001_GetDatabaseConnection();


            
        }

        private void usingToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MyClasses.Class_001_Static.F_002_Using();
        }

        private void хранимаяПроцедураToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MyClasses.Class_001_Static.F_003_XP();
        }

        private void dataSetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MyClasses.Class_001_Static.F_004_DataSet_DataAdapter();
        }

        private void dataGridViewToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String Sel = "Select * from Names";
            using(SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[1].ConnectionString))
            {
                DataSet ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(Sel, conn);

                da.Fill(ds, "name");

                dataGridView1.DataSource = ds;
                dataGridView1.DataMember = "name";

                

            }
        }

        private void изменитьЯчейкуToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataSet ds = (DataSet)dataGridView1.DataSource;
            ds.Tables[0].Rows[1][2] = "ЕЕЕ";
        }

        private void iDisponsableToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MyClasses.Class_002_Disponsable Cl = new MyClasses.Class_002_Disponsable();

            MessageBox.Show(Cl.y.ToString());
            
        }

        private void collectionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List<int> newlist = new List<int>();
            newlist.Add(5);

            System.Collections.ArrayList Abc = new System.Collections.ArrayList();

            Abc.Add(5);
            Abc.Add("zzz");

            

            

        }

        private void anonTYPEToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MyClasses.Class_001_Static.F_006_Anonim_Type();
        }

        private void интерфейсКакТипToolStripMenuItem_Click(object sender, EventArgs e)
        {//347
            MyClasses.Class_002_Disponsable base_cl = new MyClasses.Class_002_Disponsable(5);

            List<MyClasses.Class_002_Disponsable > NewMy = new List<MyClasses.Class_002_Disponsable >();
            NewMy.Add(new MyClasses.Class_002_Disponsable());
            NewMy[0].y = 1;
            NewMy[0].z = 2;
            NewMy.Add(new MyClasses.Class_002_Disponsable());
            NewMy[1].y = 11;
            NewMy[1].z = 12;
            NewMy.Add(new MyClasses.Class_002_Disponsable());
            NewMy[2].y = 21;
            NewMy[2].z = 22;

            IEnumerable<MyClasses.Class_002_Disponsable> Sel = NewMy.Where(delegate(MyClasses.Class_002_Disponsable rr)
            {
                return rr.y == 11;
            }).Select(delegate(MyClasses.Class_002_Disponsable rr)
            {
                return rr;
            }
            );

            foreach (MyClasses.Class_002_Disponsable My in Sel)
            {
                MessageBox.Show(string.Format("My.y = {0}, my.z = {1}", My.y, My.z));
            }

        }

        private void linqПовторToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List<MyClasses.Class_002_Disponsable> MyList = new List<MyClasses.Class_002_Disponsable>() { new MyClasses.Class_002_Disponsable(), new MyClasses.Class_002_Disponsable(), new MyClasses.Class_002_Disponsable() };
            MyList[0].y = 01; MyList[0].z = 02;
            MyList[1].y = 11; MyList[1].z = 12;
            MyList[2].y = 21; MyList[2].z = 22;


            IEnumerable<MyClasses.Class_002_Disponsable>  MyNum= MyList.Where(delegate (MyClasses.Class_002_Disponsable r )
            {
                return r.y >= 8;
            }).OrderByDescending(delegate(MyClasses.Class_002_Disponsable r)
            {
                return r.z;
            }).Select (delegate (MyClasses.Class_002_Disponsable r)
            {
                return r;

            });

            foreach (MyClasses.Class_002_Disponsable my in MyNum)
            {
                MessageBox.Show(string.Format("my.y = {0}, my.z = {1}", my.y, my.z));
            }

            MyList[0].y = 09; MyList[0].z = 02;
            MyList[1].y = 01; MyList[1].z = 12;
            MyList[2].y = 01; MyList[2].z = 22;
            foreach (MyClasses.Class_002_Disponsable my in MyNum)
            {
                MessageBox.Show(string.Format("my.y = {0}, my.z = {1}", my.y, my.z));
            }
        }



        private void лямбдаToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List<MyClasses.Class_002_Disponsable> MyList = new List<MyClasses.Class_002_Disponsable>() { new MyClasses.Class_002_Disponsable(), new MyClasses.Class_002_Disponsable(), new MyClasses.Class_002_Disponsable() };
            MyList[0].y = 01; MyList[0].z = 02;
            MyList[1].y = 11; MyList[1].z = 12;
            MyList[2].y = 21; MyList[2].z = 22;


            IEnumerable<Int32> MyNum = MyList.Where(r => r.y > 8).OrderByDescending(r => r.z).Select(r => r.y);

            foreach (int i in MyNum)
            {

                MessageBox.Show(string.Format("i={0}", i));
            }

            
        }

        private void ieNumeratorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int[] i = new int[] { 5, 7, 9, 12 };

            System.Collections.IEnumerator IE = i.GetEnumerator();

            IE.Reset();
            IE.MoveNext();

            MessageBox.Show(IE.Current.ToString());
            
        }

        private void linqNewNotationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List<MyClasses.Class_002_Disponsable> MyList = new List<MyClasses.Class_002_Disponsable>() { new MyClasses.Class_002_Disponsable(), new MyClasses.Class_002_Disponsable(), new MyClasses.Class_002_Disponsable() };
            MyList[0].y = 01; MyList[0].z = 02;
            MyList[1].y = 11; MyList[1].z = 12;
            MyList[2].y = 21; MyList[2].z = 22;


            IEnumerable<Int32> MyNum = from r in MyList where r.y > 8 orderby r.z descending select r.y;

            foreach (int i in MyNum)
            {

                MessageBox.Show(string.Format("i={0}", i));
            }

        }

        private void yieldToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IEnumerable<object> z = MyClasses.Class_001_Static.F_006_GetEnumerator();

            foreach (object a in z)
            {
                MessageBox.Show(string.Format("z = {0}", a));

            }
        }

        private void вывестиИзТаблицыToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Linq2Sql.F_001_get_data();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void button6_Click(object sender, EventArgs e)
        {
            MyClasses.RoomReservation rs = new MyClasses.RoomReservation();
            rs.ReserveRoom = textBox2.Text;

            Linq2Sql.F_002_set_data_Room_reserv(rs);



            
        }

        private void button7_Click(object sender, EventArgs e)
        {
            foreach (var item in Linq2Sql.F_003_GetRums())
            {
                MessageBox.Show(string.Format("item.ReservID = {0}, item.ReserveRoom = {1}", item.ReservID, item.ReserveRoom));
            }
        }



    }
}
